﻿<!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
-->
<UserControl
  x:Class="System.Windows.Controls.Samples.DomainUpDownSample"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
  xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
  xmlns:system="clr-namespace:System;assembly=mscorlib"
  xmlns:samples="clr-namespace:System.Windows.Controls.Samples">
  <UserControl.Resources>
    <!-- Ficticious businesslogic: converts a border to a string, by looking at its background color. -->
    <samples:BorderToStringConverter
      x:Key="BorderToStringConverter" />
    <!-- Parses a month business object to a string representation, using a provided culture. -->
    <samples:MonthToStringConverter
      x:Key="MonthToStringConverter" />
    <!-- Used to illustrate a custom error visual. -->
    <Style
      x:Key="CustomErrorStyle"
      TargetType="inputToolkit:DomainUpDown">
      <Setter
        Property="HorizontalContentAlignment"
        Value="Left" />
      <Setter
        Property="VerticalContentAlignment"
        Value="Center" />
      <Setter
        Property="BorderThickness"
        Value="1" />
      <Setter
        Property="Background"
        Value="#FFFFFFFF" />
      <Setter
        Property="Foreground"
        Value="#FF000000" />
      <Setter
        Property="Padding"
        Value="2" />
      <Setter
        Property="BorderBrush">
        <Setter.Value>
          <LinearGradientBrush
            EndPoint="0.5,1"
            StartPoint="0.5,0">
            <GradientStop
              Color="#FFA3AEB9"
              Offset="0" />
            <GradientStop
              Color="#FF8399A9"
              Offset="0.375" />
            <GradientStop
              Color="#FF718597"
              Offset="0.375" />
            <GradientStop
              Color="#FF617584"
              Offset="1" />
          </LinearGradientBrush>
        </Setter.Value>
      </Setter>
      <Setter
        Property="Template">
        <Setter.Value>
          <ControlTemplate
            TargetType="inputToolkit:DomainUpDown">
            <Grid
              x:Name="RootElement">
              <vsm:VisualStateManager.VisualStateGroups>
                <vsm:VisualStateGroup
                  x:Name="CommonStates">
                  <vsm:VisualState
                    x:Name="Normal" />
                  <vsm:VisualState
                    x:Name="MouseOver">
                    <Storyboard>
                      <ColorAnimationUsingKeyFrames
                        Storyboard.TargetName="MouseOverBorder"
                        Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)">
                        <SplineColorKeyFrame
                          KeyTime="0"
                          Value="#FF99C1E2" />
                      </ColorAnimationUsingKeyFrames>
                    </Storyboard>
                  </vsm:VisualState>
                  <vsm:VisualState
                    x:Name="Disabled">
                    <Storyboard>
                      <DoubleAnimationUsingKeyFrames
                        Storyboard.TargetName="DisabledVisualElement"
                        Storyboard.TargetProperty="Opacity">
                        <SplineDoubleKeyFrame
                          KeyTime="0"
                          Value="1" />
                      </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                  </vsm:VisualState>
                  <vsm:VisualState
                    x:Name="ReadOnly">
                    <Storyboard>
                      <DoubleAnimationUsingKeyFrames
                        Storyboard.TargetName="IsReadOnlyVisualElement"
                        Storyboard.TargetProperty="Opacity">
                        <SplineDoubleKeyFrame
                          KeyTime="0"
                          Value="1" />
                      </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                  </vsm:VisualState>
                </vsm:VisualStateGroup>
                <vsm:VisualStateGroup
                  x:Name="FocusStates">
                  <vsm:VisualState
                    x:Name="Focused">
                    <Storyboard>
                      <DoubleAnimationUsingKeyFrames
                        Storyboard.TargetName="FocusVisualElement"
                        Storyboard.TargetProperty="Opacity">
                        <SplineDoubleKeyFrame
                          KeyTime="0"
                          Value="1" />
                      </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                  </vsm:VisualState>
                  <vsm:VisualState
                    x:Name="Unfocused">
                    <Storyboard>
                      <DoubleAnimationUsingKeyFrames
                        Storyboard.TargetName="FocusVisualElement"
                        Storyboard.TargetProperty="Opacity">
                        <SplineDoubleKeyFrame
                          KeyTime="0"
                          Value="0" />
                      </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                  </vsm:VisualState>
                </vsm:VisualStateGroup>
                <vsm:VisualStateGroup
                  x:Name="InteractionModeStates">
                  <vsm:VisualState
                    x:Name="Edit">
                    <Storyboard>
                      <DoubleAnimation
                        Duration="0"
                        Storyboard.TargetName="Text"
                        Storyboard.TargetProperty="(UIElement.Opacity)"
                        To="1" />
                      <DoubleAnimation
                        Duration="0"
                        Storyboard.TargetName="Visualization"
                        Storyboard.TargetProperty="(UIElement.Opacity)"
                        To="0" />
                    </Storyboard>
                  </vsm:VisualState>
                  <vsm:VisualState
                    x:Name="Display" />
                </vsm:VisualStateGroup>
                <vsm:VisualStateGroup
                  x:Name="DomainStates">
                  <vsm:VisualState
                    x:Name="ValidDomain" />
                  <vsm:VisualState
                    x:Name="InvalidDomain">
                    <Storyboard>
                      <ObjectAnimationUsingKeyFrames
                        BeginTime="00:00:00"
                        Duration="00:00:00.0010000"
                        Storyboard.TargetName="ErrorVisualElement"
                        Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame
                          KeyTime="00:00:00">
                          <DiscreteObjectKeyFrame.Value>
                            <Visibility>Visible</Visibility>
                          </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                      </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                  </vsm:VisualState>
                </vsm:VisualStateGroup>
              </vsm:VisualStateManager.VisualStateGroups>
              <Border
                x:Name="Border"
                Opacity="1"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                CornerRadius="1">
                <Grid>
                  <Border
                    x:Name="ReadOnlyVisualElement"
                    IsHitTestVisible="False"
                    Opacity="0"
                    Background="#72F7F7F7" />
                  <Border
                    x:Name="MouseOverBorder"
                    BorderBrush="Transparent"
                    BorderThickness="1">
                    <Grid>
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition
                          Width="*" />
                        <ColumnDefinition
                          Width="Auto" />
                      </Grid.ColumnDefinitions>
                      <Grid
                        Margin="{TemplateBinding Padding}">
                        <ContentControl
                          x:Name="Visualization"
                          IsTabStop="False"
                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                          Margin="0"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                          FontFamily="{TemplateBinding FontFamily}"
                          FontSize="{TemplateBinding FontSize}"
                          FontStretch="{TemplateBinding FontStretch}"
                          Foreground="{TemplateBinding Foreground}"
                          Padding="0"
                          Content="{TemplateBinding Value}"
                          ContentTemplate="{TemplateBinding ItemTemplate}" />
                        <TextBox
                          x:Name="Text"
                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                          Margin="0"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                          IsHitTestVisible="false"
                          Opacity="0"
                          BorderThickness="0"
                          FontFamily="{TemplateBinding FontFamily}"
                          FontSize="{TemplateBinding FontSize}"
                          FontStretch="{TemplateBinding FontStretch}"
                          Foreground="{TemplateBinding Foreground}"
                          IsTabStop="True"
                          Padding="0"
                          AcceptsReturn="False"
                          TextWrapping="NoWrap">
                          <TextBox.Style>
                            <Style
                              TargetType="TextBox">
                              <Setter
                                Property="Template">
                                <Setter.Value>
                                  <ControlTemplate
                                    TargetType="TextBox">
                                    <ScrollViewer
                                      x:Name="ContentElement"
                                      IsHitTestVisible="false"
                                      BorderThickness="0"
                                      Padding="0" />
                                  </ControlTemplate>
                                </Setter.Value>
                              </Setter>
                            </Style>
                          </TextBox.Style>
                        </TextBox>
                      </Grid>
                      <inputToolkit:ButtonSpinner
                        x:Name="Spinner"
                        Style="{TemplateBinding SpinnerStyle}"
                        Grid.Column="1"
                        IsTabStop="False"
                        TabIndex="3" />
                    </Grid>
                  </Border>
                </Grid>
              </Border>
              <Border
                x:Name="DisabledVisualElement"
                IsHitTestVisible="False"
                Opacity="0"
                Background="#A5F7F7F7"
                BorderBrush="#A5F7F7F7"
                BorderThickness="{TemplateBinding BorderThickness}" />
              <Border
                x:Name="FocusVisualElement"
                Margin="1"
                IsHitTestVisible="False"
                Opacity="0"
                BorderBrush="#FF6DBDD1"
                BorderThickness="{TemplateBinding BorderThickness}" />
              <TextBlock
                x:Name="ErrorVisualElement"
                Visibility="Collapsed"
                VerticalAlignment="Center"
                HorizontalAlignment="Right"
                Margin="0,0,-120,0"
                Padding="0"
                Foreground="Red"
                FontSize="12"
                FontWeight="Bold"
                Text="Invalid color." />
            </Grid>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </UserControl.Resources>
  <StackPanel
    Background="White">
    <ContentControl
      Content="Styled, with multiple lines of content and ValueMemberPath"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      ItemsSource="{Binding}"
      HorizontalAlignment="Left"
      ValueMemberPath="CodeFaa"
      Height="Auto"
      FontSize="34">
      <inputToolkit:DomainUpDown.ItemTemplate>
        <DataTemplate>
          <Grid
            MinWidth="370">
            <Grid.Background>
              <SolidColorBrush
                Color="#aa000000" />
            </Grid.Background>
            <TextBlock
              Foreground="#22ffffff"
              Margin="4+0,2+0"
              FontSize="34"
              Text="{Binding CodeFaa}" />
            <StackPanel
              HorizontalAlignment="Right"
              Margin="0, 0, 8, 0">
              <TextBlock
                HorizontalAlignment="Right"
                Foreground="White"
                FontSize="12"
                Text="{Binding LimitedName}"
                Padding="2" />
              <TextBlock
                HorizontalAlignment="Right"
                Foreground="White"
                FontSize="14"
                Text="{Binding City}"
                Padding="2" />
              <TextBlock
                HorizontalAlignment="Right"
                Foreground="White"
                FontSize="14"
                Text="{Binding State}"
                Padding="2" />
            </StackPanel>
          </Grid>
        </DataTemplate>
      </inputToolkit:DomainUpDown.ItemTemplate>
    </inputToolkit:DomainUpDown>
    <ContentControl
      Content="Default"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      MinWidth="120"
      HorizontalAlignment="Left">
      <system:String>11111</system:String>
      <system:String>22222</system:String>
      <system:String>33333</system:String>
      <system:String>aaaaa</system:String>
      <system:String>bbbbb</system:String>
    </inputToolkit:DomainUpDown>
    <ContentControl
      Content="Not editable"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      IsEditable="False"
      MinWidth="120"
      HorizontalAlignment="Left">
      <system:String>11111</system:String>
      <system:String>22222</system:String>
      <system:String>33333</system:String>
      <system:String>aaaaa</system:String>
      <system:String>bbbbb</system:String>
    </inputToolkit:DomainUpDown>
    <ContentControl
      Content="Cyclic"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      IsCyclic="True"
      MinWidth="120"
      HorizontalAlignment="Left">
      <system:String>11111</system:String>
      <system:String>22222</system:String>
      <system:String>33333</system:String>
      <system:String>aaaaa</system:String>
      <system:String>bbbbb</system:String>
    </inputToolkit:DomainUpDown>
    <ContentControl
      Content="Does not allow invalid input"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      MinWidth="120"
      HorizontalAlignment="Left"
      InvalidInputAction="TextBoxCannotLoseFocus">
      <system:String>11111</system:String>
      <system:String>22222</system:String>
      <system:String>33333</system:String>
      <system:String>aaaaa</system:String>
      <system:String>bbbbb</system:String>
    </inputToolkit:DomainUpDown>
    <ContentControl
      Content="Customized error template"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      MinWidth="120"
      InvalidInputAction="TextBoxCannotLoseFocus "
      HorizontalAlignment="Left"
      Style="{StaticResource CustomErrorStyle}">
      <system:String>Red</system:String>
      <system:String>Green</system:String>
      <system:String>Blue</system:String>
      <system:String>Yellow</system:String>
      <system:String>Black</system:String>
    </inputToolkit:DomainUpDown>
    <ContentControl
      Content="accepts invalid input without fallback item"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      InvalidInputAction="UseFallbackItem"
      MinWidth="120"
      HorizontalAlignment="Left">
      <system:String>11111</system:String>
      <system:String>22222</system:String>
      <system:String>33333</system:String>
      <system:String>aaaaa</system:String>
      <system:String>bbbbb</system:String>
    </inputToolkit:DomainUpDown>
    <ContentControl
      Content="Fallback item (22222) and accepts invalid input"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      InvalidInputAction="UseFallbackItem"
      FallbackItem="22222"
      MinWidth="120"
      HorizontalAlignment="Left">
      <system:String>11111</system:String>
      <system:String>22222</system:String>
      <system:String>33333</system:String>
      <system:String>aaaaa</system:String>
      <system:String>bbbbb</system:String>
    </inputToolkit:DomainUpDown>
    <ContentControl
      Content="Using databinding"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      ItemsSource="{Binding}"
      MinWidth="120"
      HorizontalAlignment="Left" />
    <ContentControl
      Content="Styled"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      ItemsSource="{Binding}"
      ValueMemberPath="CodeFaa"
      Height="Auto"
      Width="550"
      HorizontalAlignment="Left">
      <inputToolkit:DomainUpDown.ItemTemplate>
        <DataTemplate>
          <StackPanel
            Orientation="Horizontal">
            <TextBlock
              FontWeight="Bold"
              Margin="5"
              Text="{Binding}" />
            <ContentPresenter
              Margin="5"
              Content="{Binding Name}" />
            <ContentPresenter
              Margin="5"
              Content="{Binding City}" />
            <ContentPresenter
              Margin="5"
              Content="{Binding State}" />
          </StackPanel>
        </DataTemplate>
      </inputToolkit:DomainUpDown.ItemTemplate>
    </inputToolkit:DomainUpDown>
    <ContentControl
      Content="Borders with value member binding"
      Height="Auto"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      MinWidth="120"
      Height="Auto"
      ValueMemberBinding="{Binding Converter={StaticResource BorderToStringConverter}}"
      HorizontalAlignment="Left">
      <Border
        Background="Red"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" />
      <Border
        Background="Green"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" />
      <Border
        Background="Blue"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" />
      <ToolTipService.ToolTip>
        <TextBlock
          Style="{StaticResource Information}">Valid values are Red, Green or Blue</TextBlock>
      </ToolTipService.ToolTip>
    </inputToolkit:DomainUpDown>
    <ContentControl
      Content="Month names with a converter culture set to dutch"
      Style="{StaticResource Header}" />
    <TextBlock
      Style="{StaticResource Information}">Select a culture in the list below and type a month name
    <LineBreak />in that culture. The list will be parsed according to the selected culture and matched to the typed text.
     <LineBreak />Note that changing the culture does not change the list below, it only changes the converter!</TextBlock>
    <StackPanel
      Orientation="Horizontal">
      <ComboBox
        x:Name="cultureList"
        Margin="5"
        SelectionChanged="CultureList_SelectionChanged"
        HorizontalAlignment="Left"
        DisplayMemberPath="EnglishName" />
      <inputToolkit:DomainUpDown
        x:Name="cultureDependentDUD"
        ValueMemberBinding="{Binding Converter={StaticResource MonthToStringConverter}}"
        MinWidth="300"
        Height="Auto"
        Margin="5"
        HorizontalAlignment="Left">
        <samples:Month
          Number="1"
          FriendlyName="Month 1: January" />
        <samples:Month
          Number="2"
          FriendlyName="Month 2: February" />
        <samples:Month
          Number="3"
          FriendlyName="Month 3: March" />
        <samples:Month
          Number="4"
          FriendlyName="Month 4: April" />
        <samples:Month
          Number="5"
          FriendlyName="Month 5: May" />
        <samples:Month
          Number="6"
          FriendlyName="Month 6: June" />
        <samples:Month
          Number="7"
          FriendlyName="Month 7: July" />
        <samples:Month
          Number="8"
          FriendlyName="Month 8: August" />
        <samples:Month
          Number="9"
          FriendlyName="Month 9: September" />
        <samples:Month
          Number="10"
          FriendlyName="Month 10: October" />
        <samples:Month
          Number="11"
          FriendlyName="Month 11: November" />
        <samples:Month
          Number="12"
          FriendlyName="Month 12: December" />
        <ToolTipService.ToolTip>
          <TextBlock
            Style="{StaticResource Information}"
            Text="The Dutch name for March is 'maart'." />
        </ToolTipService.ToolTip>
      </inputToolkit:DomainUpDown>
    </StackPanel>
    <ContentControl
      Content="Interception at parse error"
      Style="{StaticResource Header}" />
    <inputToolkit:DomainUpDown
      Height="Auto"
      ParseError="DomainUpDown_ParseError"
      InvalidInputAction="UseFallbackItem"
      MinWidth="120"
      ValueMemberBinding="{Binding Converter={StaticResource BorderToStringConverter}}"
      HorizontalAlignment="Left">
      <Border
        Background="Red"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" />
      <Border
        Background="Green"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" />
      <Border
        Background="Blue"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" />
      <ToolTipService.ToolTip>
        <TextBlock
          Style="{StaticResource Information}">Type a well understood name from the Colors class, like Yellow
        <LineBreak />or use correct rgba codes, like #ff444444.</TextBlock>
      </ToolTipService.ToolTip>
    </inputToolkit:DomainUpDown>
    <src:SourceViewer xmlns:src="clr-namespace:System.Windows.Controls.Samples;assembly=System.Windows.Controls.Samples.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <src:SourceFile Path="DomainUpDownSample.xaml">
    <src:SourceFile.Source>
      <sys:String>&lt;!--
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
--&gt;
&lt;UserControl
  x:Class="System.Windows.Controls.Samples.DomainUpDownSample"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
  xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
  xmlns:system="clr-namespace:System;assembly=mscorlib"
  xmlns:samples="clr-namespace:System.Windows.Controls.Samples"&gt;
  &lt;UserControl.Resources&gt;
    &lt;!-- Ficticious businesslogic: converts a border to a string, by looking at its background color. --&gt;
    &lt;samples:BorderToStringConverter
      x:Key="BorderToStringConverter" /&gt;
    &lt;!-- Parses a month business object to a string representation, using a provided culture. --&gt;
    &lt;samples:MonthToStringConverter
      x:Key="MonthToStringConverter" /&gt;
    &lt;!-- Used to illustrate a custom error visual. --&gt;
    &lt;Style
      x:Key="CustomErrorStyle"
      TargetType="inputToolkit:DomainUpDown"&gt;
      &lt;Setter
        Property="HorizontalContentAlignment"
        Value="Left" /&gt;
      &lt;Setter
        Property="VerticalContentAlignment"
        Value="Center" /&gt;
      &lt;Setter
        Property="BorderThickness"
        Value="1" /&gt;
      &lt;Setter
        Property="Background"
        Value="#FFFFFFFF" /&gt;
      &lt;Setter
        Property="Foreground"
        Value="#FF000000" /&gt;
      &lt;Setter
        Property="Padding"
        Value="2" /&gt;
      &lt;Setter
        Property="BorderBrush"&gt;
        &lt;Setter.Value&gt;
          &lt;LinearGradientBrush
            EndPoint="0.5,1"
            StartPoint="0.5,0"&gt;
            &lt;GradientStop
              Color="#FFA3AEB9"
              Offset="0" /&gt;
            &lt;GradientStop
              Color="#FF8399A9"
              Offset="0.375" /&gt;
            &lt;GradientStop
              Color="#FF718597"
              Offset="0.375" /&gt;
            &lt;GradientStop
              Color="#FF617584"
              Offset="1" /&gt;
          &lt;/LinearGradientBrush&gt;
        &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
      &lt;Setter
        Property="Template"&gt;
        &lt;Setter.Value&gt;
          &lt;ControlTemplate
            TargetType="inputToolkit:DomainUpDown"&gt;
            &lt;Grid
              x:Name="RootElement"&gt;
              &lt;vsm:VisualStateManager.VisualStateGroups&gt;
                &lt;vsm:VisualStateGroup
                  x:Name="CommonStates"&gt;
                  &lt;vsm:VisualState
                    x:Name="Normal" /&gt;
                  &lt;vsm:VisualState
                    x:Name="MouseOver"&gt;
                    &lt;Storyboard&gt;
                      &lt;ColorAnimationUsingKeyFrames
                        Storyboard.TargetName="MouseOverBorder"
                        Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"&gt;
                        &lt;SplineColorKeyFrame
                          KeyTime="0"
                          Value="#FF99C1E2" /&gt;
                      &lt;/ColorAnimationUsingKeyFrames&gt;
                    &lt;/Storyboard&gt;
                  &lt;/vsm:VisualState&gt;
                  &lt;vsm:VisualState
                    x:Name="Disabled"&gt;
                    &lt;Storyboard&gt;
                      &lt;DoubleAnimationUsingKeyFrames
                        Storyboard.TargetName="DisabledVisualElement"
                        Storyboard.TargetProperty="Opacity"&gt;
                        &lt;SplineDoubleKeyFrame
                          KeyTime="0"
                          Value="1" /&gt;
                      &lt;/DoubleAnimationUsingKeyFrames&gt;
                    &lt;/Storyboard&gt;
                  &lt;/vsm:VisualState&gt;
                  &lt;vsm:VisualState
                    x:Name="ReadOnly"&gt;
                    &lt;Storyboard&gt;
                      &lt;DoubleAnimationUsingKeyFrames
                        Storyboard.TargetName="IsReadOnlyVisualElement"
                        Storyboard.TargetProperty="Opacity"&gt;
                        &lt;SplineDoubleKeyFrame
                          KeyTime="0"
                          Value="1" /&gt;
                      &lt;/DoubleAnimationUsingKeyFrames&gt;
                    &lt;/Storyboard&gt;
                  &lt;/vsm:VisualState&gt;
                &lt;/vsm:VisualStateGroup&gt;
                &lt;vsm:VisualStateGroup
                  x:Name="FocusStates"&gt;
                  &lt;vsm:VisualState
                    x:Name="Focused"&gt;
                    &lt;Storyboard&gt;
                      &lt;DoubleAnimationUsingKeyFrames
                        Storyboard.TargetName="FocusVisualElement"
                        Storyboard.TargetProperty="Opacity"&gt;
                        &lt;SplineDoubleKeyFrame
                          KeyTime="0"
                          Value="1" /&gt;
                      &lt;/DoubleAnimationUsingKeyFrames&gt;
                    &lt;/Storyboard&gt;
                  &lt;/vsm:VisualState&gt;
                  &lt;vsm:VisualState
                    x:Name="Unfocused"&gt;
                    &lt;Storyboard&gt;
                      &lt;DoubleAnimationUsingKeyFrames
                        Storyboard.TargetName="FocusVisualElement"
                        Storyboard.TargetProperty="Opacity"&gt;
                        &lt;SplineDoubleKeyFrame
                          KeyTime="0"
                          Value="0" /&gt;
                      &lt;/DoubleAnimationUsingKeyFrames&gt;
                    &lt;/Storyboard&gt;
                  &lt;/vsm:VisualState&gt;
                &lt;/vsm:VisualStateGroup&gt;
                &lt;vsm:VisualStateGroup
                  x:Name="InteractionModeStates"&gt;
                  &lt;vsm:VisualState
                    x:Name="Edit"&gt;
                    &lt;Storyboard&gt;
                      &lt;DoubleAnimation
                        Duration="0"
                        Storyboard.TargetName="Text"
                        Storyboard.TargetProperty="(UIElement.Opacity)"
                        To="1" /&gt;
                      &lt;DoubleAnimation
                        Duration="0"
                        Storyboard.TargetName="Visualization"
                        Storyboard.TargetProperty="(UIElement.Opacity)"
                        To="0" /&gt;
                    &lt;/Storyboard&gt;
                  &lt;/vsm:VisualState&gt;
                  &lt;vsm:VisualState
                    x:Name="Display" /&gt;
                &lt;/vsm:VisualStateGroup&gt;
                &lt;vsm:VisualStateGroup
                  x:Name="DomainStates"&gt;
                  &lt;vsm:VisualState
                    x:Name="ValidDomain" /&gt;
                  &lt;vsm:VisualState
                    x:Name="InvalidDomain"&gt;
                    &lt;Storyboard&gt;
                      &lt;ObjectAnimationUsingKeyFrames
                        BeginTime="00:00:00"
                        Duration="00:00:00.0010000"
                        Storyboard.TargetName="ErrorVisualElement"
                        Storyboard.TargetProperty="(UIElement.Visibility)"&gt;
                        &lt;DiscreteObjectKeyFrame
                          KeyTime="00:00:00"&gt;
                          &lt;DiscreteObjectKeyFrame.Value&gt;
                            &lt;Visibility&gt;Visible&lt;/Visibility&gt;
                          &lt;/DiscreteObjectKeyFrame.Value&gt;
                        &lt;/DiscreteObjectKeyFrame&gt;
                      &lt;/ObjectAnimationUsingKeyFrames&gt;
                    &lt;/Storyboard&gt;
                  &lt;/vsm:VisualState&gt;
                &lt;/vsm:VisualStateGroup&gt;
              &lt;/vsm:VisualStateManager.VisualStateGroups&gt;
              &lt;Border
                x:Name="Border"
                Opacity="1"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                CornerRadius="1"&gt;
                &lt;Grid&gt;
                  &lt;Border
                    x:Name="ReadOnlyVisualElement"
                    IsHitTestVisible="False"
                    Opacity="0"
                    Background="#72F7F7F7" /&gt;
                  &lt;Border
                    x:Name="MouseOverBorder"
                    BorderBrush="Transparent"
                    BorderThickness="1"&gt;
                    &lt;Grid&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                        &lt;ColumnDefinition
                          Width="*" /&gt;
                        &lt;ColumnDefinition
                          Width="Auto" /&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;Grid
                        Margin="{TemplateBinding Padding}"&gt;
                        &lt;ContentControl
                          x:Name="Visualization"
                          IsTabStop="False"
                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                          Margin="0"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                          FontFamily="{TemplateBinding FontFamily}"
                          FontSize="{TemplateBinding FontSize}"
                          FontStretch="{TemplateBinding FontStretch}"
                          Foreground="{TemplateBinding Foreground}"
                          Padding="0"
                          Content="{TemplateBinding Value}"
                          ContentTemplate="{TemplateBinding ItemTemplate}" /&gt;
                        &lt;TextBox
                          x:Name="Text"
                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                          Margin="0"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                          IsHitTestVisible="false"
                          Opacity="0"
                          BorderThickness="0"
                          FontFamily="{TemplateBinding FontFamily}"
                          FontSize="{TemplateBinding FontSize}"
                          FontStretch="{TemplateBinding FontStretch}"
                          Foreground="{TemplateBinding Foreground}"
                          IsTabStop="True"
                          Padding="0"
                          AcceptsReturn="False"
                          TextWrapping="NoWrap"&gt;
                          &lt;TextBox.Style&gt;
                            &lt;Style
                              TargetType="TextBox"&gt;
                              &lt;Setter
                                Property="Template"&gt;
                                &lt;Setter.Value&gt;
                                  &lt;ControlTemplate
                                    TargetType="TextBox"&gt;
                                    &lt;ScrollViewer
                                      x:Name="ContentElement"
                                      IsHitTestVisible="false"
                                      BorderThickness="0"
                                      Padding="0" /&gt;
                                  &lt;/ControlTemplate&gt;
                                &lt;/Setter.Value&gt;
                              &lt;/Setter&gt;
                            &lt;/Style&gt;
                          &lt;/TextBox.Style&gt;
                        &lt;/TextBox&gt;
                      &lt;/Grid&gt;
                      &lt;inputToolkit:ButtonSpinner
                        x:Name="Spinner"
                        Style="{TemplateBinding SpinnerStyle}"
                        Grid.Column="1"
                        IsTabStop="False"
                        TabIndex="3" /&gt;
                    &lt;/Grid&gt;
                  &lt;/Border&gt;
                &lt;/Grid&gt;
              &lt;/Border&gt;
              &lt;Border
                x:Name="DisabledVisualElement"
                IsHitTestVisible="False"
                Opacity="0"
                Background="#A5F7F7F7"
                BorderBrush="#A5F7F7F7"
                BorderThickness="{TemplateBinding BorderThickness}" /&gt;
              &lt;Border
                x:Name="FocusVisualElement"
                Margin="1"
                IsHitTestVisible="False"
                Opacity="0"
                BorderBrush="#FF6DBDD1"
                BorderThickness="{TemplateBinding BorderThickness}" /&gt;
              &lt;TextBlock
                x:Name="ErrorVisualElement"
                Visibility="Collapsed"
                VerticalAlignment="Center"
                HorizontalAlignment="Right"
                Margin="0,0,-120,0"
                Padding="0"
                Foreground="Red"
                FontSize="12"
                FontWeight="Bold"
                Text="Invalid color." /&gt;
            &lt;/Grid&gt;
          &lt;/ControlTemplate&gt;
        &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
    &lt;/Style&gt;
  &lt;/UserControl.Resources&gt;
  &lt;StackPanel
    Background="White"&gt;
    &lt;ContentControl
      Content="Styled, with multiple lines of content and ValueMemberPath"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      ItemsSource="{Binding}"
      HorizontalAlignment="Left"
      ValueMemberPath="CodeFaa"
      Height="Auto"
      FontSize="34"&gt;
      &lt;inputToolkit:DomainUpDown.ItemTemplate&gt;
        &lt;DataTemplate&gt;
          &lt;Grid
            MinWidth="370"&gt;
            &lt;Grid.Background&gt;
              &lt;SolidColorBrush
                Color="#aa000000" /&gt;
            &lt;/Grid.Background&gt;
            &lt;TextBlock
              Foreground="#22ffffff"
              Margin="4+0,2+0"
              FontSize="34"
              Text="{Binding CodeFaa}" /&gt;
            &lt;StackPanel
              HorizontalAlignment="Right"
              Margin="0, 0, 8, 0"&gt;
              &lt;TextBlock
                HorizontalAlignment="Right"
                Foreground="White"
                FontSize="12"
                Text="{Binding LimitedName}"
                Padding="2" /&gt;
              &lt;TextBlock
                HorizontalAlignment="Right"
                Foreground="White"
                FontSize="14"
                Text="{Binding City}"
                Padding="2" /&gt;
              &lt;TextBlock
                HorizontalAlignment="Right"
                Foreground="White"
                FontSize="14"
                Text="{Binding State}"
                Padding="2" /&gt;
            &lt;/StackPanel&gt;
          &lt;/Grid&gt;
        &lt;/DataTemplate&gt;
      &lt;/inputToolkit:DomainUpDown.ItemTemplate&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
    &lt;ContentControl
      Content="Default"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      MinWidth="120"
      HorizontalAlignment="Left"&gt;
      &lt;system:String&gt;11111&lt;/system:String&gt;
      &lt;system:String&gt;22222&lt;/system:String&gt;
      &lt;system:String&gt;33333&lt;/system:String&gt;
      &lt;system:String&gt;aaaaa&lt;/system:String&gt;
      &lt;system:String&gt;bbbbb&lt;/system:String&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
    &lt;ContentControl
      Content="Not editable"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      IsEditable="False"
      MinWidth="120"
      HorizontalAlignment="Left"&gt;
      &lt;system:String&gt;11111&lt;/system:String&gt;
      &lt;system:String&gt;22222&lt;/system:String&gt;
      &lt;system:String&gt;33333&lt;/system:String&gt;
      &lt;system:String&gt;aaaaa&lt;/system:String&gt;
      &lt;system:String&gt;bbbbb&lt;/system:String&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
    &lt;ContentControl
      Content="Cyclic"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      IsCyclic="True"
      MinWidth="120"
      HorizontalAlignment="Left"&gt;
      &lt;system:String&gt;11111&lt;/system:String&gt;
      &lt;system:String&gt;22222&lt;/system:String&gt;
      &lt;system:String&gt;33333&lt;/system:String&gt;
      &lt;system:String&gt;aaaaa&lt;/system:String&gt;
      &lt;system:String&gt;bbbbb&lt;/system:String&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
    &lt;ContentControl
      Content="Does not allow invalid input"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      MinWidth="120"
      HorizontalAlignment="Left"
      InvalidInputAction="TextBoxCannotLoseFocus"&gt;
      &lt;system:String&gt;11111&lt;/system:String&gt;
      &lt;system:String&gt;22222&lt;/system:String&gt;
      &lt;system:String&gt;33333&lt;/system:String&gt;
      &lt;system:String&gt;aaaaa&lt;/system:String&gt;
      &lt;system:String&gt;bbbbb&lt;/system:String&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
    &lt;ContentControl
      Content="Customized error template"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      MinWidth="120"
      InvalidInputAction="TextBoxCannotLoseFocus "
      HorizontalAlignment="Left"
      Style="{StaticResource CustomErrorStyle}"&gt;
      &lt;system:String&gt;Red&lt;/system:String&gt;
      &lt;system:String&gt;Green&lt;/system:String&gt;
      &lt;system:String&gt;Blue&lt;/system:String&gt;
      &lt;system:String&gt;Yellow&lt;/system:String&gt;
      &lt;system:String&gt;Black&lt;/system:String&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
    &lt;ContentControl
      Content="accepts invalid input without fallback item"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      InvalidInputAction="UseFallbackItem"
      MinWidth="120"
      HorizontalAlignment="Left"&gt;
      &lt;system:String&gt;11111&lt;/system:String&gt;
      &lt;system:String&gt;22222&lt;/system:String&gt;
      &lt;system:String&gt;33333&lt;/system:String&gt;
      &lt;system:String&gt;aaaaa&lt;/system:String&gt;
      &lt;system:String&gt;bbbbb&lt;/system:String&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
    &lt;ContentControl
      Content="Fallback item (22222) and accepts invalid input"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      InvalidInputAction="UseFallbackItem"
      FallbackItem="22222"
      MinWidth="120"
      HorizontalAlignment="Left"&gt;
      &lt;system:String&gt;11111&lt;/system:String&gt;
      &lt;system:String&gt;22222&lt;/system:String&gt;
      &lt;system:String&gt;33333&lt;/system:String&gt;
      &lt;system:String&gt;aaaaa&lt;/system:String&gt;
      &lt;system:String&gt;bbbbb&lt;/system:String&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
    &lt;ContentControl
      Content="Using databinding"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      ItemsSource="{Binding}"
      MinWidth="120"
      HorizontalAlignment="Left" /&gt;
    &lt;ContentControl
      Content="Styled"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      ItemsSource="{Binding}"
      ValueMemberPath="CodeFaa"
      Height="Auto"
      Width="550"
      HorizontalAlignment="Left"&gt;
      &lt;inputToolkit:DomainUpDown.ItemTemplate&gt;
        &lt;DataTemplate&gt;
          &lt;StackPanel
            Orientation="Horizontal"&gt;
            &lt;TextBlock
              FontWeight="Bold"
              Margin="5"
              Text="{Binding}" /&gt;
            &lt;ContentPresenter
              Margin="5"
              Content="{Binding Name}" /&gt;
            &lt;ContentPresenter
              Margin="5"
              Content="{Binding City}" /&gt;
            &lt;ContentPresenter
              Margin="5"
              Content="{Binding State}" /&gt;
          &lt;/StackPanel&gt;
        &lt;/DataTemplate&gt;
      &lt;/inputToolkit:DomainUpDown.ItemTemplate&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
    &lt;ContentControl
      Content="Borders with value member binding"
      Height="Auto"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      MinWidth="120"
      Height="Auto"
      ValueMemberBinding="{Binding Converter={StaticResource BorderToStringConverter}}"
      HorizontalAlignment="Left"&gt;
      &lt;Border
        Background="Red"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" /&gt;
      &lt;Border
        Background="Green"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" /&gt;
      &lt;Border
        Background="Blue"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" /&gt;
      &lt;ToolTipService.ToolTip&gt;
        &lt;TextBlock
          Style="{StaticResource Information}"&gt;Valid values are Red, Green or Blue&lt;/TextBlock&gt;
      &lt;/ToolTipService.ToolTip&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
    &lt;ContentControl
      Content="Month names with a converter culture set to dutch"
      Style="{StaticResource Header}" /&gt;
    &lt;TextBlock
      Style="{StaticResource Information}"&gt;Select a culture in the list below and type a month name
    &lt;LineBreak /&gt;in that culture. The list will be parsed according to the selected culture and matched to the typed text.
     &lt;LineBreak /&gt;Note that changing the culture does not change the list below, it only changes the converter!&lt;/TextBlock&gt;
    &lt;StackPanel
      Orientation="Horizontal"&gt;
      &lt;ComboBox
        x:Name="cultureList"
        Margin="5"
        SelectionChanged="CultureList_SelectionChanged"
        HorizontalAlignment="Left"
        DisplayMemberPath="EnglishName" /&gt;
      &lt;inputToolkit:DomainUpDown
        x:Name="cultureDependentDUD"
        ValueMemberBinding="{Binding Converter={StaticResource MonthToStringConverter}}"
        MinWidth="300"
        Height="Auto"
        Margin="5"
        HorizontalAlignment="Left"&gt;
        &lt;samples:Month
          Number="1"
          FriendlyName="Month 1: January" /&gt;
        &lt;samples:Month
          Number="2"
          FriendlyName="Month 2: February" /&gt;
        &lt;samples:Month
          Number="3"
          FriendlyName="Month 3: March" /&gt;
        &lt;samples:Month
          Number="4"
          FriendlyName="Month 4: April" /&gt;
        &lt;samples:Month
          Number="5"
          FriendlyName="Month 5: May" /&gt;
        &lt;samples:Month
          Number="6"
          FriendlyName="Month 6: June" /&gt;
        &lt;samples:Month
          Number="7"
          FriendlyName="Month 7: July" /&gt;
        &lt;samples:Month
          Number="8"
          FriendlyName="Month 8: August" /&gt;
        &lt;samples:Month
          Number="9"
          FriendlyName="Month 9: September" /&gt;
        &lt;samples:Month
          Number="10"
          FriendlyName="Month 10: October" /&gt;
        &lt;samples:Month
          Number="11"
          FriendlyName="Month 11: November" /&gt;
        &lt;samples:Month
          Number="12"
          FriendlyName="Month 12: December" /&gt;
        &lt;ToolTipService.ToolTip&gt;
          &lt;TextBlock
            Style="{StaticResource Information}"
            Text="The Dutch name for March is 'maart'." /&gt;
        &lt;/ToolTipService.ToolTip&gt;
      &lt;/inputToolkit:DomainUpDown&gt;
    &lt;/StackPanel&gt;
    &lt;ContentControl
      Content="Interception at parse error"
      Style="{StaticResource Header}" /&gt;
    &lt;inputToolkit:DomainUpDown
      Height="Auto"
      ParseError="DomainUpDown_ParseError"
      InvalidInputAction="UseFallbackItem"
      MinWidth="120"
      ValueMemberBinding="{Binding Converter={StaticResource BorderToStringConverter}}"
      HorizontalAlignment="Left"&gt;
      &lt;Border
        Background="Red"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" /&gt;
      &lt;Border
        Background="Green"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" /&gt;
      &lt;Border
        Background="Blue"
        Margin="4"
        BorderThickness="1"
        BorderBrush="Black"
        Width="80"
        Height="50" /&gt;
      &lt;ToolTipService.ToolTip&gt;
        &lt;TextBlock
          Style="{StaticResource Information}"&gt;Type a well understood name from the Colors class, like Yellow
        &lt;LineBreak /&gt;or use correct rgba codes, like #ff444444.&lt;/TextBlock&gt;
      &lt;/ToolTipService.ToolTip&gt;
    &lt;/inputToolkit:DomainUpDown&gt;
  &lt;/StackPanel&gt;
&lt;/UserControl&gt;
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="DomainUpDownSample.xaml.cs">
    <src:SourceFile.Source>
      <sys:String>// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Windows.Media;
using System.Collections;
using System.Reflection;
using System.ComponentModel;
using System.Windows.Data;
using System.Collections.Generic;

namespace System.Windows.Controls.Samples
{
    /// &lt;summary&gt;
    /// Sample page demonstrating DomainUpDown.
    /// &lt;/summary&gt;
    [Sample("(0)DomainUpDown", DifficultyLevel.Basic)]
    [Category("DomainUpDown")]
    public partial class DomainUpDownSample : UserControl
    {
        #region Cultures
        /// &lt;summary&gt;
        /// Cultures that are recognized on most configurations.
        /// &lt;/summary&gt;
        private readonly string[] _cultureNames = new[]
                                             {
                                                     "af", "af-ZA", "ar", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-LY",
                                                     "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SY", "ar-TN", "ar-YE", "az", "az-Cyrl-AZ", "az-Latn-AZ", "be",
                                                     "be-BY", "bg", "bg-BG", "ca", "ca-ES", "cs", "cs-CZ", "da", "da-DK", "de", "de-AT", "de-CH", "de-DE",
                                                     "de-LI", "de-LU", "dv", "dv-MV", "el", "el-GR", "en", "en-029", "en-AU", "en-BZ", "en-CA", "en-GB", "en-IE", 
                                                     "en-JM", "en-NZ", "en-PH", "en-TT", "en-US", "en-ZA", "en-ZW", "es", "es-AR", "es-BO", "es-CL", "es-CO",
                                                     "es-CR", "es-DO", "es-EC", "es-ES", "es-GT", "es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY",
                                                     "es-SV", "es-UY", "es-VE", "et", "et-EE", "eu", "eu-ES", "fa", "fa-IR", "fi", "fi-FI", "fo", "fo-FO", "fr",
                                                     "fr-BE", "fr-CA", "fr-CH", "fr-FR", "fr-LU", "fr-MC", "gl", "gl-ES", "gu", "gu-IN", "he", "he-IL", "hi",
                                                     "hi-IN", "hr", "hr-HR", "hu", "hu-HU", "hy", "hy-AM", "id", "id-ID", "is", "is-IS", "it", "it-CH", "it-IT",
                                                     "ja", "ja-JP", "ka", "ka-GE", "kk", "kk-KZ", "kn", "kn-IN", "ko", "kok", "kok-IN", "ko-KR", "ky", "ky-KG",
                                                     "lt", "lt-LT", "lv", "lv-LV", "mk", "mk-MK", "mn", "mn-MN", "mr", "mr-IN", "ms", "ms-BN", "ms-MY", "nb-NO",
                                                     "nl", "nl-BE", "nl-NL", "nn-NO", "no", "pa", "pa-IN", "pl", "pl-PL", "pt", "pt-BR", "pt-PT", "ro", "ro-RO",
                                                     "ru", "ru-RU", "sa", "sa-IN", "sk", "sk-SK", "sl", "sl-SI", "sq", "sq-AL", "sr", "sr-Cyrl-CS", "sr-Latn-CS", 
                                                     "sv", "sv-FI", "sv-SE", "sw", "sw-KE", "syr", "syr-SY", "ta", "ta-IN", "te", "te-IN", "th", "th-TH", "tr", 
                                                     "tr-TR", "tt", "tt-RU", "uk", "uk-UA", "ur", "ur-PK", "uz", "uz-Cyrl-UZ", "uz-Latn-UZ", "vi", "vi-VN",
                                                     "zh-CHS", "zh-CHT", "zh-CN", "zh-HK", "zh-MO", "zh-SG", "zh-TW"
                                             };
        #endregion

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref="DomainUpDownSample"/&gt; class.
        /// &lt;/summary&gt;
        public DomainUpDownSample()
        {
            InitializeComponent();

            Loaded += DomainUpDownSample_Loaded;
        }

        /// &lt;summary&gt;
        /// Handles the Loaded event of the DomainUpDownSample control.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.RoutedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
        private void DomainUpDownSample_Loaded(object sender, RoutedEventArgs e)
        {
            IEnumerable airports = Airport.SampleAirports;
            DataContext = airports;

            List&lt;CultureInfo&gt; cultures = new List&lt;CultureInfo&gt;();

            // work through long list of cultures and check if it is actually 
            // allowed in this configuration.
            foreach (string cultureName in _cultureNames)
            {
                try
                {
                    CultureInfo c = new CultureInfo(cultureName);
                    cultures.Add(c);
                }
                catch (ArgumentException)
                {
                }
            }

            cultureList.ItemsSource = cultures;
            // preselect dutch, if allowed.
            cultureList.SelectedItem = cultures.FirstOrDefault(info =&gt; info.Name == "nl-NL");
        }

        /// &lt;summary&gt;
        /// Handles the ParseError event of the DomainUpDown control.
        /// If a color can be found to, a new border will be added to our items collection.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.Branched.UpDownParseErrorEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Used by event defined in Xaml.")]
        private void DomainUpDown_ParseError(object sender, UpDownParseErrorEventArgs e)
        {
            DomainUpDown dud = (DomainUpDown)sender;

            // get the text that was unable to parse.
            string text = e.Text;

            SolidColorBrush backgroundColor = null;

            // is might be a known color string, like "Yellow" 
            // get by looking at the Colors class.
            PropertyInfo colorPropertyInfo = typeof(Colors).GetProperty(text, BindingFlags.Static | BindingFlags.Public);
            if (colorPropertyInfo != null)
            {
                backgroundColor = new SolidColorBrush((Color)colorPropertyInfo.GetValue(null, new object[] { }));
            }
            else
            {
                // it might be rgba code, like #aarrggbb
                if (text.StartsWith("#", StringComparison.OrdinalIgnoreCase) &amp;&amp; text.Length == 9)
                {
                    // rrggbbaa
                    text = text.Substring(1);

                    // test to see if it can be parsed to an int
                    int result;
                    if (Int32.TryParse(text, out result))
                    {
                        byte[] rgba = new byte[4];
                        for (int i = 0; i &lt; 4; i++)
                        {
                            rgba[i] = Byte.Parse(text.Substring(i * 2, 2), CultureInfo.CurrentCulture);
                        }
                        backgroundColor = new SolidColorBrush(new Color { A = rgba[0], B = rgba[3], G = rgba[2], R = rgba[1] });
                    }
                }
            }

            if (backgroundColor != null)
            {
                dud.Items.Add(new Border
                {
                    Width = 120,
                    Height = 80,
                    Background = backgroundColor,
                    BorderBrush = new SolidColorBrush(Colors.Yellow),
                    BorderThickness = new Thickness(4)
                });
                dud.CurrentIndex = dud.Items.Count - 1;
            }
        }

        /// &lt;summary&gt;
        /// Handles the SelectionChanged event of the CultureList control.
        /// &lt;/summary&gt;
        /// &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;
        /// &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Used by event defined in Xaml.")]
        private void CultureList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CultureInfo c = cultureList.SelectedItem as CultureInfo;
            if (c != null)
            {
                Binding copy = new Binding(cultureDependentDUD.ValueMemberPath)
                {
                    Converter = cultureDependentDUD.ValueMemberBinding.Converter,
                    ConverterCulture = c
                };
                cultureDependentDUD.ValueMemberBinding = copy;
            }
        }
    }
}
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
  <src:SourceFile Path="DomainUpDownSample.xaml.vb">
    <src:SourceFile.Source>
      <sys:String>' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License (Ms-PL).
' Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
' All other rights reserved.

Imports System.Windows.Data
Imports Microsoft.VisualBasic
Imports System
Imports System.Globalization
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports System.Collections
Imports System.Reflection
Imports System.ComponentModel
Imports System.Collections.Generic

''' &lt;summary&gt;
''' Sample page demonstrating DomainUpDown.
''' &lt;/summary&gt;
&lt;Sample("(0)DomainUpDown", DifficultyLevel.Basic), Category("DomainUpDown")&gt; _
Partial Public Class DomainUpDownSample
    Inherits UserControl
#Region "Cultures"
    ''' &lt;summary&gt;
    ''' Cultures that are recognized on most configurations.
    ''' &lt;/summary&gt;
    Private ReadOnly _cultureNames As String() = New String() {"af", "af-ZA", "ar", "ar-AE", "ar-BH", "ar-DZ", _
                "ar-EG", "ar-IQ", "ar-JO", "ar-KW", "ar-LB", "ar-LY", _
                "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SY", "ar-TN", _
                "ar-YE", "az", "az-Cyrl-AZ", "az-Latn-AZ", "be", "be-BY", _
                "bg", "bg-BG", "ca", "ca-ES", "cs", "cs-CZ", _
                "da", "da-DK", "de", "de-AT", "de-CH", "de-DE", _
                "de-LI", "de-LU", "dv", "dv-MV", "el", "el-GR", _
                "en", "en-029", "en-AU", "en-BZ", "en-CA", "en-GB", _
                "en-IE", "en-JM", "en-NZ", "en-PH", "en-TT", "en-US", _
                "en-ZA", "en-ZW", "es", "es-AR", "es-BO", "es-CL", _
                "es-CO", "es-CR", "es-DO", "es-EC", "es-ES", "es-GT", _
                "es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", _
                "es-PY", "es-SV", "es-UY", "es-VE", "et", "et-EE", _
                "eu", "eu-ES", "fa", "fa-IR", "fi", "fi-FI", _
                "fo", "fo-FO", "fr", "fr-BE", "fr-CA", "fr-CH", _
                "fr-FR", "fr-LU", "fr-MC", "gl", "gl-ES", "gu", _
                "gu-IN", "he", "he-IL", "hi", "hi-IN", "hr", _
                "hr-HR", "hu", "hu-HU", "hy", "hy-AM", "id", _
                "id-ID", "is", "is-IS", "it", "it-CH", "it-IT", _
                "ja", "ja-JP", "ka", "ka-GE", "kk", "kk-KZ", _
                "kn", "kn-IN", "ko", "kok", "kok-IN", "ko-KR", _
                "ky", "ky-KG", "lt", "lt-LT", "lv", "lv-LV", _
                "mk", "mk-MK", "mn", "mn-MN", "mr", "mr-IN", _
                "ms", "ms-BN", "ms-MY", "nb-NO", "nl", "nl-BE", _
                "nl-NL", "nn-NO", "no", "pa", "pa-IN", "pl", _
                "pl-PL", "pt", "pt-BR", "pt-PT", "ro", "ro-RO", _
                "ru", "ru-RU", "sa", "sa-IN", "sk", "sk-SK", _
                "sl", "sl-SI", "sq", "sq-AL", "sr", "sr-Cyrl-CS", _
                "sr-Latn-CS", "sv", "sv-FI", "sv-SE", "sw", "sw-KE", _
                "syr", "syr-SY", "ta", "ta-IN", "te", "te-IN", _
                "th", "th-TH", "tr", "tr-TR", "tt", "tt-RU", _
                "uk", "uk-UA", "ur", "ur-PK", "uz", "uz-Cyrl-UZ", _
                "uz-Latn-UZ", "vi", "vi-VN", "zh-CHS", "zh-CHT", "zh-CN", _
                "zh-HK", "zh-MO", "zh-SG", "zh-TW"}
#End Region

    ''' &lt;summary&gt;
    ''' Initializes a new instance of the &lt;see cref="DomainUpDownSample"/&gt; class.
    ''' &lt;/summary&gt;
    Public Sub New()
        InitializeComponent()
    End Sub

    ''' &lt;summary&gt;
    ''' Handles the Loaded event of the DomainUpDownSample control.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.RoutedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
    Private Sub DomainUpDownSample_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles Me.Loaded
        Dim airports As IEnumerable = Airport.SampleAirports
        DataContext = airports

        Dim cultures As New List(Of CultureInfo)()
        Dim dutch As CultureInfo = Nothing

        ' work through long list of cultures and check if it is actually 
        ' allowed in this configuration.
        For Each cultureName As String In _cultureNames
            Try
                Dim c As New CultureInfo(cultureName)
                If (cultureName = "nl-NL") Then
                    dutch = c
                End If

                cultures.Add(c)
            Catch generatedExceptionName As ArgumentException
            End Try
        Next

        cultureList.ItemsSource = cultures
        ' preselect dutch, if allowed.
        If (dutch IsNot Nothing) Then
            cultureList.SelectedItem = dutch
        End If

    End Sub

    ''' &lt;summary&gt;
    ''' Handles the ParseError event of the DomainUpDown control.
    ''' If a color can be found to, a new border will be added to our items collection.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.Branched.UpDownParseErrorEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
    &lt;System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Used by event defined in Xaml.")&gt; _
    Private Sub DomainUpDown_ParseError(ByVal sender As Object, ByVal e As UpDownParseErrorEventArgs)
        Dim dud As DomainUpDown = CType(sender, DomainUpDown)

        ' get the text that was unable to parse.
        Dim text As String = e.Text

        Dim backgroundColor As SolidColorBrush = Nothing

        ' is might be a known color string, like "Yellow" 
        ' get by looking at the Colors class.
        Dim colorPropertyInfo As PropertyInfo = GetType(Colors).GetProperty(text, BindingFlags.Static Or BindingFlags.Public)
        If colorPropertyInfo IsNot Nothing Then
            backgroundColor = New SolidColorBrush(CType(colorPropertyInfo.GetValue(Nothing, New Object() {}), Color))
        Else
            ' it might be rgba code, like #aarrggbb
            If text.StartsWith("#", StringComparison.OrdinalIgnoreCase) AndAlso text.Length = 9 Then
                ' rrggbbaa
                text = text.Substring(1)

                ' test to see if it can be parsed to an int
                Dim result As Integer
                If Int32.TryParse(text, result) Then
                    Dim rgba(3) As Byte
                    For i As Integer = 0 To 3
                        rgba(i) = Byte.Parse(text.Substring(i * 2, 2), CultureInfo.CurrentCulture)
                    Next i
                    backgroundColor = New SolidColorBrush(New Color With {.A = rgba(0), .B = rgba(3), .G = rgba(2), .R = rgba(1)})
                End If
            End If
        End If

        If backgroundColor IsNot Nothing Then
            dud.Items.Add(New Border With _
            { _
                .Width = 120, _
                .Height = 80, _
                .Background = backgroundColor, _
                .BorderBrush = New SolidColorBrush(Colors.Yellow), _
                .BorderThickness = New Thickness(4) _
            })
            dud.CurrentIndex = dud.Items.Count - 1
        End If
    End Sub

    ''' &lt;summary&gt;
    ''' Handles the SelectionChanged event of the CultureList control.
    ''' &lt;/summary&gt;
    ''' &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;
    ''' &lt;param name="e"&gt;The &lt;see cref="System.Windows.Controls.SelectionChangedEventArgs"/&gt; instance containing the event data.&lt;/param&gt;
    &lt;System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification:="Used by event defined in Xaml.")&gt; _
    Private Sub CultureList_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        Dim c As CultureInfo = TryCast(cultureList.SelectedItem, CultureInfo)
        If c IsNot Nothing Then
            Dim copy As Binding = New Binding(cultureDependentDUD.ValueMemberPath)
            copy.Converter = cultureDependentDUD.ValueMemberBinding.Converter
            copy.ConverterCulture = c
            cultureDependentDUD.ValueMemberBinding = copy
        End If
    End Sub
End Class
</sys:String>
    </src:SourceFile.Source>
  </src:SourceFile>
</src:SourceViewer>
  </StackPanel>
</UserControl>
